<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Term extends MY_Controller {

	function __construct() {
		parent::__construct();

		$this->load->helper('url');
		$this->load->helper('form');

		//$this->output->cache(0.5);

	}

	public function index1() {
		$data['title'] = "MyHome - 我的家园";
		$data['heading'] = "MyHome";
		//load->library
		$this->load->library('pagination');

		//load->model
		$this->load->model('MY_Blog');

		//$data
		$config['per_page'] = '2';
		$config['total_rows'] = $this->MY_Blog->count_all();
		$offset = 0;
		if($this->uri->segment(2)) {
			$offset = $this->uri->segment(2);
			$data['title'] = "Page  " . ($offset / $config['per_page'] + 1) . "/" . ceil($config['total_rows'] / $config['per_page']) . " - ".$data['title'];
		}
		$data['blogs'] = $this->MY_Blog->get($config['per_page'], $offset);
		$data['title'] =  "首页 - " . $data['title'];

		//pagination
		$config['base_url'] = site_url('page');
		$config['uri_segment'] = 2;
		$this->pagination->initialize($config);
		$data['page'] = $this->pagination->create_links();

		//load->view
		$this->load->view('header', $data);
		$this->load->view('blog_view', $data);
		$this->load->view('sidebar');
		$this->load->view('footer');
	}

	public function category() {
		$term_id=$this->uri->segment(2);
		$page=$this->uri->segment(4);
		$data['title'] = "MyHome - 我的家园";
		$data['heading'] = "MyHome";
		//load->library
		$this->load->library('pagination');
		//load->model
		$this->load->model('MTerm');

		//$this->Post->update_veiws($pid);
		//$data
		$config['per_page'] = '2';
		$config['total_rows'] = $this->MTerm->count_all($term_id);
		$offset = 0;
		if($page) {
			$offset = $page;
			$data['title'] = "Page  " . ($offset / $config['per_page'] + 1) . "/" . ceil($config['total_rows'] / $config['per_page']) . " - ".$data['title'];
		}
		$data['lists'] = $this->MTerm->get_list($term_id,$config['per_page'], $offset);
		if(!$data['lists']) {
			show_404();
		}
		$data['category_row'] = $this->MTerm->get_name($term_id);

		//pagination
		$config['base_url'] = site_url(array('category', $term_id, 'page'));
		$config['uri_segment'] = 4;
		$this->pagination->initialize($config);
		$data['page'] = $this->pagination->create_links();

		//$data['title'] = $data['lists']->post_title . " - ".$data['title'];
		//load->view

		$this->load->view('header', $data);
		$this->load->view('category_view', $data);
		$this->load->view('sidebar');
		$this->load->view('footer');
	}

}

/* End of file term.php */
/* Location: ./application/controllers/term.php */